package com.lovo.web.controller;

import com.lovo.web.bean.BuyCarBean;
import com.lovo.web.bean.UserOrderBean;
import com.lovo.web.service.IBuyCarService;
import com.lovo.web.vo.OrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("buyCar")
public class BuyCarController {
    @Autowired
    private IBuyCarService buyCarService;
    @GetMapping("add")
    public String add(BuyCarBean buyCar){
        buyCarService.add(buyCar);
        return "ok";
    }
    @RequestMapping("findAllByUserId/{userId}")
    public List<BuyCarBean> findAllByUserId(@PathVariable("userId") long userId) {
        return buyCarService.findAllByUserId(userId);
    }
    @RequestMapping("updateNumByBuyCarId/{buyCarId}/{newNum}")
    public String updateNumByBuyCarId(@PathVariable("buyCarId")long buyCarId,@PathVariable("newNum") int newNum) {
        buyCarService.updateNumByBuyCarId(buyCarId,newNum);
        return "ok";
    }
    @RequestMapping("delByBuyCarId/{buyCarId}")
    public String delByBuyCarId(@PathVariable("buyCarId")long buyCarId) {
        buyCarService.delByBuyCarId(buyCarId);
        return "ok";
    }
    @PostMapping("delBuyCarAndCreateOrder")
    public String delBuyCarAndCreateOrder(@RequestBody OrderVo orderVo) {
        return buyCarService.delBuyCarAndCreateOrder(orderVo.getBuyCarIdList(), orderVo.getOrderList());
    }
    @RequestMapping("buyProduct")
    public String buyProduct(@RequestBody UserOrderBean order) {
        return buyCarService.buyProduct(order);
    }
}
